package com.hmall.api.interceptors;/**
 * @author wl
 * @version 1.0
 * @since 2025-09-06 12:20
 */

import com.hmall.common.utils.UserContext;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 *des:hm-item
 *data Created in 2025-09-06 12-20
 */
@Slf4j
@Component
public class FeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        Long userId = UserContext.getUser();
        log.warn("openfeign拦截器，传递用户信息：{}",userId);
        if (Objects.nonNull(userId)){
            requestTemplate.header("user-info",userId.toString());
        }
    }
}
